package com.clps.digital.dao.impl;

import com.clps.digital.dao.PropertyDao;
import com.clps.digital.model.entity.Property;
import com.clps.digital.model.entity.User;
import com.clps.myssm.basedao.BaseDAO;

import java.util.List;

/**
 * @Author: 小炎子
 * @Date: 2024/9/2 下午3:57
 * @Description: 用户资产dao实现类
 **/
public class PropertyDaoImpl extends BaseDAO<Property> implements PropertyDao {


    @Override
    public List<Property> getProperty(Long userId) {
        return selectList("SELECT * from dbo.[property] where [userId] = ?", userId);
    }

    @Override
    public void saveProperty(Property property) {
        insertOrUpdate("UPDATE dbo.[property] SET [quantity] = ? where [id] = ?",property.getQuantity(),property.getId());
    }

    @Override
    public void addProperty(Property property) {
        insertOrUpdate("INSERT INTO dbo.[property] ([userId], [currencyId], [quantity]) VALUES (?, ?, ?)", property.getUserId(),property.getCurrencyId(),property.getQuantity());
    }

    @Override
    public void updateProperty(Property property) {
        insertOrUpdate("UPDATE dbo.[property] SET [quantity] = ? where [userId] = ? AND [currencyId] = ?", property.getQuantity(),property.getUserId(),property.getCurrencyId());

    }

    @Override
    public Property getByIdProperty(User user) {
        return selectOne("SELECT * from dbo.[property] where [userId] = ?", user.getId());
    }

    @Override
    public Property getByCurrencyProperty(Long userId, Long currencyId) {
        return selectOne("SELECT * from dbo.[property] where [userId] = ? And [currencyId] = ?", userId, currencyId);
    }
}
